﻿using System.Drawing;
using System;

namespace HurlBat.XEdit2D
{
    internal class ImageData
    {
        string path;
        public string Path { get { return path; } }

        Bitmap thumbnail;
        public Bitmap Thumbnail { get { return thumbnail; } }

        public ImageData(string path)
        {
            this.path = path;
            int size = 50;
            thumbnail = new Bitmap(size, size);
            Graphics g = Graphics.FromImage(thumbnail);
            Image img = Image.FromFile(this.path);
            float scale = (float)size / Math.Max(img.Width, img.Height);
            int scaleWidth = (int)Math.Round(img.Width * scale);
            int scaleHeight = (int)Math.Round(img.Height * scale);
            g.DrawImage(img,
                new Rectangle((size - scaleWidth) / 2, (size - scaleHeight) / 2, scaleWidth, scaleHeight),
                new Rectangle(0, 0, img.Size.Width, img.Size.Height),
                GraphicsUnit.Pixel);
        }
    }
}
